<?php

namespace Modules\Admin\Http\Controllers;

use Illuminate\Support\Facades\Request;
use Modules\Admin\Service\RepairstoreService;

class RepairstoreController extends BaseController
{
    /**
     * 维修店列表
     */
    public function index()
    {
        $data = Request::input();
        $list = RepairstoreService::getList($data);
//dd($list);
        return view('admin::repairstore.index', ['list' => $list, 'data' => $data]);
    }


    /*******************************************维修站商品*************************************************/

    /**
     * 维修店(商品)列表
     */
    public function goodsList()
    {
        $data = Request::input();
        $list = RepairstoreService::getGoodsList($data);

        echo_error($list);
        return view('admin::repairstore.goods', ['list' => $list, 'data' => $data]);
    }

    /**
     * 添加商品
     */
    public function create()
    {
        $type = RepairstoreService::getGoodsType();

        return view('admin::repairstore.create', ['type' => $type]);
    }

    /**
     * 添加商品
     */
    public function store()
    {
        $data = Request::all();

        shiwu_start();
        $res = RepairstoreService::addOne((array)$data);
        shiwu_end($res);

        return $res;
    }


    /**
     * 编辑
     */
    public function edit()
    {
        $id = (int)Request::get('id', 0);
        $data = RepairstoreService::getOne((int)$id);

        $type = RepairstoreService::getGoodsType();

        return view('admin::repairstore.edit', ['data' => $data, 'type' => $type]);
    }

    /**
     * 编辑
     */
    public function update()
    {
        $arrInput = Request::all();

        shiwu_start();
        $res = RepairstoreService::editOne((array)$arrInput);
        shiwu_end($res);

        return $res;
    }

    /**
     * 删除商品图片
     */
    public function delPic()
    {
        $data = Request::all();

        return RepairstoreService::delPic((int)$data['id']);
    }

    /**
     * 删除商品
     */
    public function del()
    {
        $data = (int)Request::get('id', 0);

        return RepairstoreService::delGoods($data);
    }


}
